package com.wu.cloud.userservice.service;

import bean.ServiceInvokeResultEntity;
import exceptions.RemoteServiceException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @author xwu36
 */
@Slf4j
@ControllerAdvice
public class ExceptionAdvice {

    @ExceptionHandler(RemoteServiceException.class)
    public ServiceInvokeResultEntity RemoteService(HttpServletRequest request, HttpServletResponse response, Exception e) {
        ServiceInvokeResultEntity serviceInvokeResultEntity = new ServiceInvokeResultEntity<>();
        serviceInvokeResultEntity.setSuccess(false)
                .setMsg("远程服务异常").setTimestamp(System.currentTimeMillis())
                .setData(null).setUrl(request.getRequestURI());
        return serviceInvokeResultEntity;
    }

}
